#include "CEUtilities.h"

#include "CEGUIElementBase.h"


CEGUIElementBase::CEGUIElementBase(CEGUIElementBase * parent, int id, string name, int offsetX, int offsetY, int width, int height,
							   bool enable, bool visible, int tabindex, bool tabEnable)
{
	m_pParent = parent;
	m_nID = id;
	m_strName = name;

	SetPosition(offsetX, offsetY);
	SetSize(width, height);

	m_bEnable = enable;
	m_bVisible = visible;
	
	m_bTabEnable = tabEnable; 
	m_iTabIndex = tabindex;

	m_bFocus = false;

	m_iShowLevel = 0;
	m_eType = GUI_Default;
}


bool CEGUIElementBase::IsVisible() const
{
	return m_bVisible;
}

bool CEGUIElementBase::IsEnable() const
{
	return m_bEnable;
}

bool CEGUIElementBase::IsOnFocus() const
{
	return m_bFocus;
}


const Position& CEGUIElementBase::GetPosition() const
{
	return m_Position;
}

const Position& CEGUIElementBase::GetOffsetFromParent() const
{
	return m_OffsetFromParent;
}


const Size& CEGUIElementBase::GetSize() const
{
	return m_Size;
}

const string& CEGUIElementBase::GetName() const
{
	return m_strName;
}

int CEGUIElementBase::GetID() const
{
	return m_nID;

}


CEGUIElementBase * CEGUIElementBase::GetParent()
{
	return m_pParent;
}



void CEGUIElementBase::SetVisible(bool bVisible)
{
	m_bVisible = bVisible;
}

void CEGUIElementBase::SetPosition(int offsetX, int offsetY)
{
	m_OffsetFromParent.x = offsetX;
	m_OffsetFromParent.y = offsetY;
	if (m_pParent)
		m_Position = m_pParent->GetPosition() + m_OffsetFromParent;
	else
		m_Position = m_OffsetFromParent;
}

void CEGUIElementBase::Move(int offsetx, int offsety)
{
	m_OffsetFromParent.x += offsetx;
	m_OffsetFromParent.y += offsety;
	if (m_pParent)
		m_Position = m_pParent->GetPosition() + m_OffsetFromParent;
	else
		m_Position = m_OffsetFromParent;
}

void CEGUIElementBase::SetSize(int width, int height)
{
	m_Size.x = width;
	m_Size.y = height;
}


void CEGUIElementBase::SetName(const string& name)
{
	m_strName = name;
}

void CEGUIElementBase::SetFocus(bool focused)
{
	m_bFocus = focused;
}


void CEGUIElementBase::SetID(int id)
{
	m_nID = id;
}


void CEGUIElementBase::SetEnable(bool bEnable)
{
	m_bEnable = bEnable;
}


void CEGUIElementBase::SetParent(CEGUIElementBase* pParent)
{
	m_pParent = pParent;
	Move(0,0);
}


HRESULT CEGUIElementBase::OneTimeInit()
{ 
//	SetSize(m_Size.x, m_Size.y); 
	return S_OK; 
}

int CEGUIElementBase::GetShowLevel()
{
	return m_iShowLevel;
}

void CEGUIElementBase::SetShowLevel(int level)
{
	m_iShowLevel = level;
}


CEGUIElementType CEGUIElementBase::GetType()
{
	return m_eType;
}